import logging
import cgi
import os
#import json
from incl import *
from data_objects import *
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class GetList(webapp.RequestHandler):
  def get(self): 
    fromItem = 0
    fromItem = int(self.request.get('from', default_value='0'))
    itemsCount = int(self.request.get('count', default_value='10'))
    recipes = Recipes.all().order('-pub_date').fetch(limit=itemsCount, offset=fromItem)
    template_values = {
      'recipes': recipes
    }
    path = os.path.join(os.path.dirname(__file__), 'recipes-list.html')
    self.response.out.write(template.render(path, template_values))
    
def main():
  application = webapp.WSGIApplication(
    [('/rpc/recipes/get_new', GetList),
    ], debug=True)
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
